﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Imaging;

public partial class pages_Captcha : System.Web.UI.Page
{
    private Random random = new Random();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Session["CaptchaImageText"] = GenerateRandomCode();

            CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 400, 100, "Time new roman");

            this.Response.Clear();
            this.Response.ContentType = "image/jpeg";

            ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);

            ci.Dispose();
        }

    }

    private string GenerateRandomCode()
    {
        string s = "";
        for (int i = 0; i < 5; i++)
            s = String.Concat(s, this.random.Next(10).ToString());
        return s;
    }
}